/*
 Copyright (C) 2011 QDSS.org. All rights reserved.
 QDSS.org PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.qdss.oapi4j.util.support;

/**
 * 具有自动等待/唤醒功能
 * 
 * @author <a href="mailto:zhaofang123@gmail.com">Zhao Fangfang</a>
 * @date 2011-3-25
 * @version $Id: WakeHolder.java 38 2011-09-27 08:48:34Z zhaofang123@gmail.com $
 */
public abstract class WakeHolder extends AbstractHolder {
	
	private boolean limited = false;
	
	/**
	 * 设置是否受限
	 * 
	 * @param limited
	 */
	protected void setLimited(boolean limited) {
		this.limited = limited;
	}
	
	/**
	 * 是否受限
	 * 
	 * @return
	 */
	public boolean isLimited() {
		return limited;
	}
	
	/**
	 * 如果受限则等待1分钟
	 */
	protected void waitIfLimited() {
		waitIfLimited(60 * 1000);
	}
	
	/**
	 * 如果受限则等待
	 * 
	 * @param waitMillis 等待时间，单位毫秒
	 */
	protected void waitIfLimited(int waitMillis) {
		if (!isLimited()) {
			return;
		}
		
		try {
			Thread.sleep(waitMillis);
		} catch (InterruptedException ex) {
			Thread.currentThread().interrupt();
		}
	}
}
